package com.phaeton.beemeup.entity;

import java.util.UUID;
import java.util.Map.Entry;

import org.andengine.entity.IEntity;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import android.util.Log;

import com.phaeton.beemeup.GameManager;
import com.phaeton.beemeup.constants.SceneConstants;

public class Bee extends Insect{
	static final int MAX_HEALTH = 100;
	
	public Bee(float pX, float pY, GameManager pGameManager) {
		super(pX, pY, pGameManager.getActivity().getSceneManager().getTiledTexture("Bee"), pGameManager);
	}
	
	public int getHoney(){
		return getResource();
	}
	
	public void changeHoney(int i){
		changeResource(i);
	}
	
	public void setHoney(int i){
		setResource(i);
	}
	@Override
	public int getMaxHealth(){
		return MAX_HEALTH;
	}
	@Override
	public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
		if(pSceneTouchEvent.isActionUp()){
			if(mGameManager.getSelectedBee() == null && (state & INJURED) == 0) {
				for (Entry<UUID, Bee> entry : mGameManager.getBees().entrySet()) {
			        if (this.equals(entry.getValue())) {
			        	mGameManager.setSelectedBee(entry.getKey());
			        }
			    }
				
				Log.e("Bee", "selected Bee " + mGameManager.getSelectedBee());
				
				mGameManager.getSelectedSprite().animate(100);
				mGameManager.getLevel().getChildByIndex(SceneConstants.LAYER_COMBS).attachChild(mGameManager.getSelectedSprite());
				
				return true;
			}/*else if((this.getState() & (REGENERATION | DUMPING | FIGHT | COLLECTING | FLY)) == 0 && this.getHealth() < this.getMaxHealth()){
				Bee bee = mGameManager.getBees().get(mGameManager.getSelectedBee());
				
				if(bee.getHoney() > 0){
					bee.setTarget(this);
					bee.fly();
				}
				return true;
			}*/
		}
		return false;
	}
}
